(function(){
	if(!window.cell) window.cell={};
	if(!window.cell.clipbord) window.cell.clipbord={};
	if(!window.$clipbord) window.$clipbord = cell.clipbord= function(val) {
		if ( window == this || !this.init ){
			return new cell.clipbord(val);
		}
		return this.init(val);
	}
	cell.clipbord.fn = cell.clipbord.prototype = {
		version:"2.0.0",
		svcWStr:Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString),
		svcClip:Components.classes["@mozilla.org/widget/clipboard;1"].createInstance(Components.interfaces.nsIClipboard),
		svcTrans:Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable),
		init:function(val){
			if(!val){
				return this.paste();
			}else{
				this["val"]=val;
				return this.copy();
			}
		},
		copy:function(){
			if (!this.svcWStr) return false;
			this.svcWStr.data=this["val"];

			if (!this.svcTrans) return false;
			this.svcTrans.addDataFlavor("text/unicode");
			this.svcTrans.setTransferData("text/unicode",this.svcWStr,this["val"].length*2);

			if (!this.svcClip) return false;
			this.svcClip.emptyClipboard(this.svcClip.kGlobalClipboard);
			this.svcClip.setData(this.svcTrans,null,this.svcClip.kGlobalClipboard);
		},
		paste:function(){
			if (!this.svcClip) return false;

			if (!this.svcTrans) return false;
			this.svcTrans.addDataFlavor("text/unicode");
			
			this.svcClip.getData(this.svcTrans, this.svcClip.kGlobalClipboard);  
			var str= new Object();  
			var strLength = new Object();  
			this.svcTrans.getTransferData("text/unicode", str, strLength);
			
			if (str) str= str.value.QueryInterface(Components.interfaces.nsISupportsString);  
			if (str) pastetext = str.data.substring(0, strLength.value / 2);
			return pastetext;
		},
	}
})();